<script setup lang="ts">
import ConsultItem from './ConsultItem.vue'
import type { ConsultOrderItem } from '@/types/consult'
import type { ConsultType } from '@/enums'
import { getOrderRecordsAPI } from '@/services/consult'
import { ref } from 'vue'
interface Props {
  type: ConsultType
}
const props = defineProps<Props>()

const list = ref<ConsultOrderItem[]>([])
const loading = ref(false)
const total = ref(99999)
const current = ref(1)

const onLoad = async () => {
  const res = await getOrderRecordsAPI({
    type: props.type,
    pageSize: 5,
    current: current.value
  })
  loading.value = false
  current.value++
  total.value = res.data.total
  list.value.push(...res.data.rows)
}

const onDel = (id: string) => {
  list.value = list.value.filter((item) => item.id !== id)
}
</script>

<template>
  <div class="consult-list">
    <van-list
      v-model:loading="loading"
      @load="onLoad"
      :finished="list.length >= total"
      finished-text="没有更多数据了"
    >
      <consult-item v-for="item in list" :key="item.id" :item="item" @on-del="onDel" />
    </van-list>
  </div>
</template>

<style lang="scss" scoped>
.consult-list {
  padding: 10px 15px;
}
</style>
